package com.impzx.restaurant.rest.service;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.zxpan.restaurant.db.model.Food;
import com.zxpan.restaurant.persist.dao.FoodDao;

@Path("/food")
public class FoodService {
	
	@Autowired
	private FoodDao foodDao;
	
	@Path("/getFood")
	@GET
	public String getFood(@QueryParam("hotelId") String hotelId, @QueryParam("foodId") String foodId) {
		Food food = foodDao.getFood(hotelId, foodId);
		if(null != food) {
			return  JSON.toJSONString(food);
		} else {
			return "";
		}
	}
	
	@Path("/getCategoryFood")
	@GET
	public String getCategoryFood(@QueryParam("hotelId") String hotelId, @QueryParam("categoryId") String categoryId) {
		List<Food> foodList = foodDao.getCategory(hotelId, categoryId);
		if(null != foodList) {
			return  JSON.toJSONString(foodList);
		} else {
			return "";
		}
	}
	
	@Path("/getHotelFood")
	@GET
	public String getHotelFood(@QueryParam("hotelId") String hotelId) {
		List<Food> foodList = foodDao.getHotelFood(hotelId);
		if(null != foodList) {
			return  JSON.toJSONString(foodList);
		} else {
			return "";
		}
	}
	
	@Path("/search")
	@GET
	public String searchFood(@QueryParam("hotelId") String hotelId, @QueryParam("keyword") String keyword) {
		System.out.println(hotelId + "==" + keyword);
//		keyword = "%" + keyword + "%";
		List<Food> foodList;
			foodList = foodDao.searchFood(hotelId, keyword);
			if(null != foodList && foodList.size() != 0) {
				return JSON.toJSONString(foodList);
			} else {
				return "no";
			}
	}
}
